<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body>

<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">文章标题</label>
    <div class="layui-input-block">
      <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">文章内容</label>
    <div class="layui-input-block">
       <textarea id="content" style="display: none;"></textarea>
    </div>
  </div>
  
   <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">文章分类</label>
      <div class="layui-input-inline">
        <select name="category">
          <option value="">请选择分类</option>
          <option value="1">java</option>
          <option value="2">c++</option>
          <option value="3">web</option>
          <option value="4">database</option>
        </select>
      </div>
    </div>
  </div>
  
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="post_submit">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>

<script src="../layui/layui.js"></script>
<script>
//一般直接写在一个js文件中
layui.use(['layedit', 'form'], function() {
  var layedit = layui.layedit;
  var form = layui.form;
  var index = layedit.build('content'); //建立编辑器
  
  // 用layui内置的jquery
  var $ = layui.$;
  
  // 监听form表单的提交
  form.on('submit(post_submit)', function(data) {
	  data.field.content = layedit.getContent(index);
	 
	  console.log(data.field);
	  
	  // http://localhost/blog/post_add
	  $.get("../post_add", data.field, function(data) {
		  console.log(data);
	  });

	return false;
  });
});
</script> 

</body>
</html>